package com.wlza.syslog;

import com.wlza.commons.PropertyUtils;
import org.graylog2.syslog4j.Syslog;
import org.graylog2.syslog4j.SyslogConstants;
import org.graylog2.syslog4j.SyslogIF;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;

public class Client {

    public static final String HOST = PropertyUtils.getProperty("syslog.server.remote.host");
    private static final int PORT = Integer.parseInt(PropertyUtils.getProperty("syslog.server.remote.port"));

    private SyslogIF syslog;

    public Client(){
        syslog = Syslog.getInstance(SyslogConstants.UDP);
        syslog.getConfig().setHost(HOST);
        syslog.getConfig().setPort(PORT);
    }

    public void send(String message) {
        try {
            syslog.log(10, URLDecoder.decode(message, "UTF-8"));
        } catch (UnsupportedEncodingException e) {
            throw new RuntimeException(e);
        }
    }

    public static void main(String[] a) {
        Client client=new Client();
        client.send("{dfdfsdfsdfssssssssssssss}");
    }
}